﻿//记住用户名
function rememberUser() {
    if ($("#rememberUser").attr("checked") == 'checked') {
        var userName = $("#userName").val();
        $.cookie("rememberUser", "true", { expires: 7 }); // 存储一个带7天期限的cookie 
        $.cookie("userName", userName, { expires: 7 }); // 存储一个带7天期限的cookie 
    }
    else {
        $.cookie("rememberUser", "false", { expires: -1 });
        $.cookie("userName", '', { expires: -1 });
    }
}

//勾选记住用户名
var $rememberUser = $("#rememberUser")
$rememberUser.click(function (e) {
    if ($rememberUser.attr("checked") == undefined) {
        $rememberUser.attr("checked", 'checked');
    }
    else {
        $rememberUser.removeAttr("checked");
    }
});

$(function () {
    //加载的时候判断是否记住用户名
    if ($.cookie("rememberUser") == "true") {
        $("#rememberUser").attr("checked", true);
        $("#userName").val($.cookie("userName"));
    }

    //登陆表单验证
    $("#loginForm").validate({
        rules: {
            userName: {
                required: true
            },
            passWord: {
                required: true
            }
        },
        submitHandler: function (form) {
            rememberUser();
            form.submit();
        }
    });
});